package YanShen;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Scanner;

public class RoleManage {
    private final ArrayList role = new ArrayList();
    public RoleManage(){
        role.add(new Role("魈","风属性","* * * * *",1,90,"帅"));
        role.add(new Role("枫原万叶","风属性","* * * * *",0,90,"舔狗"));
        role.add(new Role("胡桃","火属性","* * * * *",1,89,"呆呆桃"));
        role.add(new Role("夜兰","水属性","* * * * *",0,89,"御姐"));
        role.add(new Role("雷电将军","雷属性","* * * * *",0,89,"奶香一刀"));
        role.add(new Role("纳西妲","草属性","* * * * *",1,89,"小小萝莉"));
        role.add(new Role("神里绫华","冰属性","* * * * *",0,90,"你是神里绫华的狗"));
        role.add(new Role("行秋","水属性","* * * *",6,89,"打工人"));
    }
    public void addRole(Role ro){
        role.add(ro);
    }
    public void showRole(){
        role.forEach(o -> System.out.println(o));
    }

    public void gradeSort(){
        for (int i = 0; i < role.size() - 1 ; i++) {
            for (int j = 0; j < role.size() - 1 - i ; j++) {
                Role ro1 = (Role) role.get(j);
                Role ro2 = (Role) role.get(j + 1);
                if (ro1.getGrade() < ro2.getGrade()) {
                    role.set(j,ro2);
                    role.set(j + 1,ro1);
                }
            }
        }
    }

    public void consteSort(){
        role.sort(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Role r1 = (Role) o1;
                Role r2 = (Role) o2;
                return r1.getConstellation() - r2.getConstellation();
            }
        });
    }

    public void removeGrade(int grade){
        Iterator iterator =role.iterator();
        while (iterator.hasNext()){
            Role r1 = (Role) iterator.next();
            if (r1.getGrade() < grade){
               iterator.remove();
            }
        }
    }

    public void raritySort(){
        role.sort(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Role r1 = (Role) o1;
                Role r2 = (Role) o2;
                return r1.getRarity().compareTo(r2.getRarity());
            }
        });
    }
    static Scanner sc = new Scanner(System.in);
    static RoleManage roleManage = new RoleManage();
    public static void main(String[] args) {
        while (true) {
            menu();
        }
    }
    public static void menu(){
        System.out.println("****原神之家****");
        System.out.println("1.添加角色");
        System.out.println("2.展示角色");
        System.out.println("3.按照等级排序");
        System.out.println("4.按照命座排序");
        System.out.println("5.删除角色等级不满90级的角色");
        System.out.println("6.按照稀有度排序");
        System.out.println("0.退出");
        System.out.println("请输入你的操作类型：");
        int op = sc.nextInt();
        switch (op) {
            case 1 -> add();
            case 2 -> roleManage.showRole();
            case 3 ->{
                roleManage.gradeSort();
                roleManage.showRole();
            }
            case 4 -> {
                roleManage.consteSort();
                roleManage.showRole();
            }
            case 5 ->{
                roleManage.removeGrade(90);
                roleManage.showRole();
            }
            case 6 ->{
                roleManage.raritySort();
                roleManage.showRole();
            }
            case 0 -> System.exit(1);
        }
    }
    public static void add(){
        System.out.println("请输入角色名：");
        String name = sc.next();
        System.out.println("请输入角色属性：");
        String attribute = sc.next();
        System.out.println("请输入角色稀有度：");
        String rarity = sc.next();
        System.out.println("请输入角色命座：");
        int constellation = sc.nextInt();
        System.out.println("请输入角色等级：");
        int grade = sc.nextInt();
        System.out.println("请输入角色特点：");
        String characteristic = sc.next();
        Role role = new Role(name, attribute, rarity, constellation, grade,characteristic);
        roleManage.addRole(role);
    }
}

